// Count1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>

int countone_1(int num)
{
	int sum = 0;
	while (num)
	{
		if (num % 2 == 1)
			sum++;
		num /= 2;
	}
	
	return sum;
}

int countone_2(int num)
{
	int sum = 0;
	while (num)
	{
		sum += num & 0x01;
		num >>= 1;
	}
	
	return sum;
}

int countone_3(int num)
{
	int sum = 0;
	while (num)
	{
		num &= (num-1);
		sum++;
	}
	
	return sum;
}

int _tmain(int argc, _TCHAR* argv[])
{
	printf("countone_1:%d\n", countone_1(100));
	printf("countone_2:%d\n", countone_2(100));
	printf("countone_3:%d\n", countone_3(100));
	
	return 0;
}

